home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / SCANTREE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-18  |  1.2 KB  |  48 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <mem.h>
  4.  
  5. typedef struct {
  6.              char Name[9];
  7.              char Ext[4];
  8.              char Attribute;
  9.     unsigned int  Date;
  10.     unsigned int  Time;
  11.     unsigned long Size;
  12.              int  Tag;
  13. } FileStruc;
  14.  
  15. FileStruc *XScanDir( char *Mask, int Type );
  16. char *FileName( FileStruc *f );
  17.  
  18. extern int ScdirDone;
  19.  
  20. #define DTASIZE 43
  21.  
  22. int ScanTree( char *path, char *filespec, int (*FN)(FileStruc *f, char *p) )
  23. {
  24.     char mask[80], s[80];
  25.     FileStruc *fs;
  26.     char far *TempDta;
  27.     char Dta[DTASIZE];
  28.  
  29.     sprintf( mask, "%s%s", path, filespec );
  30.     ScdirDone = 1;
  31.     while ( ( fs = XScanDir( mask, 0xff ) ) != NULL ) {
  32.         if ( -1 == FN( fs, path ) ) return( -1 );
  33.     }
  34.     sprintf( mask, "%s*.*", path );
  35.     while ( ( fs = XScanDir( mask, FA_DIREC ) ) != NULL ) {
  36.         if ( fs->Attribute & FA_DIREC ) {
  37.             TempDta = getdta();
  38.             movedata( FP_SEG(TempDta), FP_OFF(TempDta), _DS, (unsigned) Dta, DTASIZE );
  39.             sprintf( s, "%s%s\\", path, FileName( fs ) );
  40.             if ( -1 == ScanTree( s, filespec, FN ) ) return( -1 );
  41.             ScdirDone = 0;
  42.             setdta( TempDta );
  43.             movedata( _DS, (unsigned) Dta, FP_SEG(TempDta), FP_OFF(TempDta), DTASIZE );
  44.         }
  45.     }
  46.     return( 1 );
  47. }
  48.